package cn.newgrand.netcall.muc;

import java.util.HashMap;
import java.util.Map;

import org.jivesoftware.spark.ui.rooms.GroupChatRoom;

public class ChinaGroupManager {
	//由于群用的是修改会议室的策略，而会议室需要在用户加入到会议 的时候才能获取到消息
    //所以修改群的策略为，在每一次netcall登入的时候自动加入到会议室，chatcontainer中关闭的时候不退出会议室
    //最后成功接收群消息
    private static Map<String,GroupChatRoom> chinaGroupMap = new HashMap<String,GroupChatRoom>(); 
    private static final Object LOCK = new Object();
    private static ChinaGroupManager instance = null;
    
    public static ChinaGroupManager getInstance(){
    	if(null == instance){
    		synchronized(LOCK){
    			instance =  new ChinaGroupManager();
    			return instance;
    		}
    	}else 
    		return instance;
    }
    private ChinaGroupManager(){}
    
    public Map<String,GroupChatRoom> getCachedChinaGroups(){
    	return chinaGroupMap;
    }
    
    public void cacheChinaGroup(GroupChatRoom gcr){
    	chinaGroupMap.put(gcr.getRoomname(),gcr);
    }
    
    public GroupChatRoom getCachedChinaGroup(String roomJID){
    	return chinaGroupMap.get(roomJID);
    }
    
    public void removeCachedChinaGroup(String roomJID){
    	chinaGroupMap.remove(roomJID);
    }
}
